﻿package kliment.display.draw.shape {
	import flash.display.Graphics;
	import flash.geom.Point;

	import kliment.display.draw.DrawStyle;
	import kliment.display.draw.style.LineStyle;

	/**
	 * ...
	 * @author Kliment
	 */
	public class LinesShape extends ShapeAbstract {

		public function LinesShape(position:Point, points:Array, drawStyle:DrawStyle = null) {
			super();

			draw(graphics, position, points, drawStyle);
		}

		static public function draw(target:Graphics, position:Point, points:Array, drawStyle:DrawStyle):void {
			var currentPoint:Point = points[0] as Point;

			if (currentPoint.x == Point(points[points.length - 1]).x &&
				currentPoint.y == Point(points[points.length - 1]).y) {

			}else {
				if (!drawStyle)
					drawStyle = new DrawStyle(null, new LineStyle(1));
				else{
					drawStyle = drawStyle.clone();
					drawStyle.fillColorStyle = null;
					drawStyle.fillGradientStyle = null;
					drawStyle.fillBitmap = null;
				}
				if (!drawStyle.lineStyle)
					drawStyle.lineStyle = new LineStyle(1);
			}
			_setStyles(target, drawStyle);

			target.moveTo(currentPoint.x, currentPoint.y);
			for (var i:Number = 1; i < points.length; i++){
				currentPoint = points[i] as Point;
				target.lineTo(currentPoint.x, currentPoint.y);
			}
			target.endFill();
		}
	}

}